<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>待发短信</title>
	<meta name="decorator" content="default"/>
	<script src="${ctxStatic}/docheck/docheck.js" type="text/javascript"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		
		function showTestModal(smsContent){
			$('#smsSendContent').val(smsContent);
			$('#smsContentSize').text(smsContent.length);
			$('#smsContentModal').modal('show');
		}

        //查看明细
        function onSendView(id){
            var url = "${ctx}/sms/smsSend/smsSendListCheckMore?id="+id;
            windowOpen(url,id,800,450);
        }

        //通知 0 设置成功 1设置失败
        function checkSendStatus(type,sendStatus){
            var ids = getCheckboxValue("id");
            if(!ids){
                alert("请选择要处理的记录");
            }else {
                setSendStatus(ids, type, sendStatus);
            }
        }

		//通知 0 设置成功 1设置失败
		function setSendStatus(id, type,sendStatus){
			var status = "审核成功"
			if (sendStatus.indexOf("F")!=-1) {

				var actionUrl = "${ctx}/sms/smsSend/setSendStatus?ids=" + id + "&type=" + type + "&sendStatus=" + sendStatus;
				status = "失败";
				top.$.jBox.confirm("确认设置状态为"+status+"吗？选择是，修改状态，选择否，取消修改","系统提示",function(v,h,f) {
					if (v == "ok") {
						$.ajax({
								   url: actionUrl,
								   success: function (data) {
									   alert(data);
									   page();
								   },
								   error: function () {
									   alert("设置失败");
								   },
								   dataType: "text"
							   });
					}
				},{buttonsFocus:1});
				top.$('.jbox-body .jbox-icon').css('top','55px');
			}else{
				var actionUrl1 = "${ctx}/sms/smsSend/waitSendBatchForm?ids=" + id ;
				window.location.href=actionUrl1;
			}

		}



	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/sms/smsSend/list?sendStatus=D">待发短信</a></li>
		<!--<shiro:hasPermission name="sms:smsSend:edit"><li><a href="${ctx}/sms/smsSend/form">短信发送添加</a></li></shiro:hasPermission>-->
	</ul>
	<form:form id="searchForm" modelAttribute="smsSend" action="${ctx}/sms/smsSend/waitToSent" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<input id="isEffective" name="isEffective" type="hidden" value="1"/>
		<input id="sendStatus" name="sendStatus" type="hidden" value="D"/>
			<li><label>内容查询：</label>
				<form:textarea path="smsContent" rows="3" cols="11" id="smsContent" htmlEscape="false" class="input-medium"/>
			</li>
			<li><label>用户ID：</label>
				<form:input path="userid" htmlEscape="false" maxlength="11" class="input-medium"/>
			</li>
			<li><label>手机号码：</label>
				<form:input path="phoneFind" htmlEscape="false" maxlength="32" class="input-medium"/>
			</li>
			<li><label>运营商：</label>
				<form:select path="phoneType" class="input-medium">
					<form:option value="" label="全部"/>
					<form:options items="${fns:getDictList('phone_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</li>
			<li><label>网关：</label>
				<form:select path="gatewayId" class="input-medium">
					<form:option value="" label="全部"/>
					<form:options items="${fns:getGatewayList()}" itemLabel="gwName" itemValue="id" htmlEscape="false"/>
				</form:select>
			</li>
			<li><label>网关组：</label>
				<form:select path="gatewayGroup" class="input-medium">
					<form:option value="" label="全部"/>
					<form:options items="${fns:getGatewayGroupList()}" itemLabel="name" itemValue="id" htmlEscape="false"/>
				</form:select>
			</li>
			<li><label>是否批量：</label>
				<form:select path="showLevel" class="input-medium">
					<form:option value="" label="全部"/>
					<form:options items="${fns:getDictList('showLevel')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
			</li>

			<li><label>发送时间：</label>
				<input name="sendTimeQ" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
					value="<fmt:formatDate value="${smsSend.sendTimeQ}" pattern="yyyy-MM-dd HH:mm:ss"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss',isShowClear:false});"/>
			</li>
			<li><label>本页号码数：</label>
				<form:input path="count" htmlEscape="false"  class="input-medium" value="${count}"/>
			</li>
			<li class="btns"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/></li>
		<ul class="ul-form">
			<li class="btns"><input id="sendSuccSubmit" type="button" class="btn btn-primary" value="发送成功" onclick="javasrcipt:checkSendStatus(1,'TOOO');" /></li>
			<li class="btns"><input id="sendFailSubmit" type="button" class="btn btn-primary" value="发送失败" onclick="javasrcipt:checkSendStatus(1,'FOO1');" /></li>
			<%--<li class="btns"><input id="againSubmit" class="btn btn-primary" type="submit" value="重新提交网关" onclick="javasrcipt:checkSendStatus(1,'FOO1');" /></li>--%>

			<li class="clearfix"></li>
		</ul>
	</form:form>
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th><input type="checkbox" onclick="doCheckAll(this,'id', this.checked)"></th>
				<th>提交时间</th>
				<th>定时时间</th>
				<shiro:hasPermission name="sms:smsSend:devloper">
					<th>提单号</th>
				</shiro:hasPermission>
				<th>公司名称</th>
				<th>账户名称</th>
				<th>短信内容　　　　　　　　　　　　　　　　</th>
				<th>计数</th>
				<th>状态</th>
				<th>原因</th>
				<th>重发次数</th>
				<th>网关组</th>
				<th>通道</th>
				<shiro:hasPermission name="sms:smsSend:edit"><th>操作</th></shiro:hasPermission>

			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="smsSend">
			<tr onclick="selectTr(this, '${smsSend.id}' ,'id')">
				<td><input type="checkbox" name="id" id="${smsSend.id}" value="${smsSend.id}" onclick="if(this.checked){this.checked=false;}else{this.checked=true;}"></td>
				<td>
					<fmt:formatDate value="${smsSend.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
				</td>
				<td>
					<c:if test="${smsSend.sendTime != null}">
						<fmt:formatDate value="${smsSend.sendTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
					</c:if>
				</td>
				<shiro:hasPermission name="sms:smsSend:devloper">
					<td>
						${smsSend.taskid}
					</td>
				</shiro:hasPermission>
				<td>
					<a href="javascript:onSendView('${smsSend.id}')">
							${fns:getUserById(smsSend.userid).companyShortname}
					</a>
				</td>
				<td>
						${fns:getUserById(smsSend.userid).loginName} | ${fns:getDictLabel(smsSend.smsType, 'service_id', smsSend.smsType)}
				</td>
				<td>
						${fn:substring(smsSend.smsContent, 0, 20)}...
					<a href="javascript:showTestModal('${fns:escapeHtml(smsSend.smsContent)}')">[更多查看]</a>
				</td>
				<td>
						${smsSend.smsSize}
				</td>
				<td>
						${fns:getDictLabel(smsSend.sendStatus, 'sendStatus', smsSend.sendStatus)}
						<%--${fns:startsWith(smsSend.sendStatus,'T') ? '发送成功' : '发送失败'}--%>
				</td>
				<td>
						<%--原因--%>
						${smsSend.waitReason}
				</td>
				<td>
						<%--重发次数--%>
				</td>

				<td>
						<%--网关组--%>
						${fns:getGatewayGroupById(smsSend.gatewayGroup).name}
				</td>
				<td>
						${smsSend.gatewayId}
				</td>
				<shiro:hasPermission name="sms:smsSend:edit"><td>
					<a href="${ctx}/sms/smsSend/waitSendForm?id=${smsSend.id}">编辑网关或组</a>
					<a href="javascript:setSendStatus('${smsSend.id}',1,'F001')">置为失败</a>
				</td></shiro:hasPermission>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
	
	<!-- 短信内容 -->
	<div class="modal fade" style="display:none;" id="smsContentModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
   		<div class="modal-dialog">
      		<div class="modal-content">
        		<div class="modal-header">
            		<button type="button" class="close" 
               			data-dismiss="modal" aria-hidden="true">
                  		&times;
            		</button>
		            <h4 class="modal-title" id="myModalLabel">
		              	短信内容
		            </h4>
         		</div>
         		<div class="modal-body">
         			<form id="gateWaySendForm" class="form-horizontal">
	                	<div class="control-group">
	                     	<div class="controls1">
	                         	<textarea style="width:498px;" readonly="readonly" name="smsSendContent" id="smsSendContent" rows="6" cols="8"></textarea>
	                         	共 <label name="smsContentSize" id="smsContentSize"></label>  个字。
	                     	</div>
	                 	</div>
                 	</form>
         		</div>
      		</div><!-- /.modal-content -->
		</div><!-- /.modal -->
	</div>
	<!-- END -->
	
</body>
</html>